package com.hok.misc.jdbc;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Calendar;

public class InertXdr {
	public static void main(String[] args){
	}
	
	public static void insertGsmTmp() {
		Connection connection = ConnectDB.getOracleconnection();
//		Calendar time = Calendar.getInstance();
		String sql = "insert into gsm_tmp(CHARGE_MODE,SESSION_CREATE_TIME,SESSION_UPDATE_TIME," +
				"SESSION_ID,A_NUMBER,NOTIFY_TYPE,START_TIME,redo_condition_id) " +
				"values(?,?,?,?,?,?,?,?)";
				PreparedStatement prest = null;
				try {
					prest = connection.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);  
					connection.setAutoCommit(false);
					long start = System.currentTimeMillis();
					for (int i = 0; i < 2000; i++) {
						for(int j = 0; j < 1000; j++){  
							prest.setInt(1, j);  
							prest.setDate(2, new Date(System.currentTimeMillis()));
							prest.setDate(3, new Date(System.currentTimeMillis()));  
							int v = i+j;
							prest.setInt(4, v);  
							prest.setString(5, String.valueOf(v));  
							prest.setInt(6, 22);  
							prest.setDate(7, new Date(System.currentTimeMillis()));  
							prest.setLong(8, 1000);
							prest.addBatch();  
						}  
						 prest.executeBatch();  
						 connection.commit();  
					}
					System.out.println("use:" + (System.currentTimeMillis() - start));
				} catch (SQLException e) {
					e.printStackTrace();
				} finally {
					try {
						if (prest != null) {
							prest.close();
						}
						if (connection != null) {
							connection.close();
						}
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
		
	}
	
	public static void insertGprs() {
	//	insert into :tmpTableName<sql> (select t.*, '' REDO_CONDITION_ID from :tableName<sql> t where :whereSql<sql>)
		Connection connection = ConnectDB.getOracleconnection();
		System.out.println(connection);
		Calendar time = Calendar.getInstance();
		time.set(Calendar.DAY_OF_MONTH, 29);
		String sql = "insert into gprs_20110928  (select * from usage_gprs) ";
		Statement st = null;
		try {
			st = connection.createStatement();
			long start = System.currentTimeMillis();
			boolean flag = st.execute(sql);
			System.out.println("use:" + (System.currentTimeMillis() - start) + " " + flag);
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				if (st != null) {
					st.close();
				}
				if (connection != null) {
					connection.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	
	
}
